package service

import (
	"encoding/json"
	"errors"
	"fmt"
	"gin-chat/models"
	"gin-chat/router/response"
)

//FriendsList 获取好友列表
func FriendsList(UUID int64) []*response.FriendsResponse {
	userMgr := models.CUserMgr()
	user, err := userMgr.GetFromUUID(int(UUID))
	userId := user.ID
	if err != nil {
		errors.New("用户信息获取失败")
	}
	friendsMgr := models.CFriendsMgr()
	userHaveFriend, err := friendsMgr.GetFromUserID(userId)
	fmt.Printf("userHaveFriend===%+v\n", userHaveFriend[0])
	/*columnList := util.ArrayColumn(userHaveFriend, "FriendID")
	result, err := userMgr.GetBatchFromID(columnList)
	if err!=nil {
		fmt.Println("查询好友详情失败")
	}
	marshal, err := json.Marshal(result)
	if err!=nil {
		fmt.Println("序列化失败")
	}*/
	marshal, err := json.Marshal(userHaveFriend)
	var responses []*response.FriendsResponse
	json.Unmarshal(marshal, &responses)

	return responses
}
